package com.trigsoft.applist;

import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.view.View;
import android.widget.ImageView;
import android.widget.SimpleCursorAdapter;
import android.widget.TextView;

class StatisticsViewBinder implements SimpleCursorAdapter.ViewBinder
{
	public boolean setViewValue(View view, Cursor cursor, int columnIndex)
	{
		String name = cursor.getString(cursor.getColumnIndex(DBHelper.KEY_LABEL));
		if (columnIndex == cursor.getColumnIndex(DBHelper.KEY_ICON))
		{
			if (IconCache.icons.containsKey(name))
			{
				((ImageView) view).setImageBitmap(IconCache.icons.get(name));
			} else
			{
				byte[] b = cursor.getBlob(columnIndex);
				Bitmap bitmap = BitmapFactory.decodeByteArray(b, 0, b.length);
				IconCache.icons.put(name, bitmap);
				((ImageView) view).setImageBitmap(bitmap);
			}
		} else if (columnIndex == cursor.getColumnIndex(DBHelper.KEY_LABEL))
		{

			((TextView) view).setText(name);
		} else if (view.getId() == R.id.count)
		{
			((TextView) view).setText(Integer.toString(cursor.getInt(columnIndex)));
		}
		return true;
	}
}
